package com.u.social.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.u.common.api.ApiResponse;
import com.u.social.entity.User;
import com.u.social.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Alex Wu
 * @since 2025-02-17
 */
@Slf4j
@RestController
@RequestMapping("/userInfo")
public class UserInfoController {

    @Autowired
    private IUserService userService;

    @GetMapping("/{id}")
    public ApiResponse<String> getUserById(@PathVariable(value = "id") Long id) {
        User user = userService.getById(id);
        log.info("查询用户id:{}", id);
        log.info("查询用户:{}", ApiResponse.success("hello"));
        return ApiResponse.success("hello");
    }

    @PostMapping("/password")
    public ApiResponse<User>  getUserByPassword(@RequestParam String username,@RequestParam  String password) {
        User user = userService.getOne(new QueryWrapper<>(User.class)
                .eq("name", username)
                .eq("password", password));
        if (user != null) {
            return ApiResponse.success(user);
        } else {
            return ApiResponse.fail(400, "用户名或密码错误");
        }
    }
}
